package com.example.good.controller;

import com.example.good.service.IEmailService;
import com.example.good.util.JsonResult;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@CrossOrigin(value = "http://localhost:8086")
@RequestMapping("email")
@RestController
public class EmailController extends BaseController{
    @Autowired
    private IEmailService emailService;
    @RequestMapping("send")
    public JsonResult<Void> sendEmail(
            String email,
            HttpSession session) throws TencentCloudSDKException {
        Integer uid = getUidFromSession(session);
        emailService.sendEmail(uid,email);
        return new JsonResult<>(OK);
    }
    @RequestMapping("check")
    public JsonResult<Void> checkEmail(
            String CheckNum,
            String email,
            HttpSession session){
        Integer uid = getUidFromSession(session);
        emailService.checkEmail(uid,email,CheckNum);
        return new JsonResult<>(OK);
    }
}
